<?php

include ('../session.php');
include ('../db.php');
include ('config.php');

$output = '';

$output .= "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
  <head>
    <title>Panic Points - View Raid</title>
    <link href=\"../general.css\" rel=\"stylesheet\" type=\"text/css\">
  </head>
  <body>";

include ('navigation.php');

$c_raidid = intval ($raidid);

$query = "select raids.event_id, event_name, raids.location_id, location_name, raid_date, COUNT(attendees.member_id) as attendeecount
          from " . DKP_RAIDS . " as raids
          left outer join " . DKP_ATTENDEES . " as attendees
          on attendees.raid_id = raids.raid_id
          inner join " . DKP_LOCATIONS . " as locations
          on locations.location_id = raids.location_id
          inner join " . DKP_EVENTS . " as events
          on events.event_id = raids.event_id
          where raids.raid_id = $c_raidid
          group by raids.raid_id";
$result = mysql_query ($query);

$row = mysql_fetch_array ($result);

$output .= "
    <span class=\"listtitle\">raid data</span>
    <table cellspacing=\"0\" cellpadding=\"0\" style=\"padding: 2px; margin: 0px; border: 1px solid #cccccc\">
      <tr>
        <td class=\"listheader\">location</td>
        <td style=\"text-align: right; padding-left: 10px\"><a href=\"viewlocation.php?locationid=" . $row['location_id'] . "\">" . $row['location_name'] . "</td>
      </tr>
      <tr>
        <td class=\"listheader\">event</td>
        <td style=\"text-align: right; padding-left: 10px\"><a href=\"viewevent.php?eventid=" . $row['event_id'] . "\">" . $row['event_name'] . "</td>
      </tr>
      <tr>
        <td class=\"listheader\">date</td>
        <td style=\"text-align: right; padding-left: 10px\">" . $row['raid_date'] . "</td>
      </tr>
        <td class=\"listheader\">attendees</td>
        <td style=\"text-align: right; padding-left: 10px\">" . $row['attendeecount'] . "</td>
      </tr>
    </table>";

$query = "select members.member_id, members.member_name as member_name, joins.member_id as joined_id, joins.member_name as joined_name
          from " . DKP_RAIDS . " as raids
          inner join " . DKP_ATTENDEES . " as attendees
          on attendees.raid_id = raids.raid_id
          inner join " . DKP_MEMBERS . " as members
          on members.member_id = attendees.member_id
          left outer join " . DKP_MEMBERS . " as joins
          on joins.member_id = attendees.joined_id
          where raids.raid_id = $c_raidid
          order by member_name asc";
$result = mysql_query ($query);

echo mysql_error ();

$output .= "
    <span class=\"listtitle\">attendees</span>
    <table class=\"list\" cellspacing=\"0\" cellpadding=\"0\">
      <tr class=\"listheader\">
        <td>attendee</td>
      </tr>";

$i = 0;
while ($row = mysql_fetch_array ($result))
{
  $i++;

  $output .= "
      <tr class=\"" . ($i & 1 ? "listodd" : "listeven") . "\">";

  /* If an alt was used in this raid */
  if ($row['joined_id'])
  {
    $output .= "
        <td><a href=\"viewmember.php?memberid=" . $row['joined_id'] . "\">" . $row['joined_name'] . "</a> <span style=\"font-style: italic\">(<a href=\"viewmember.php?memberid=" . $row['member_id'] . "\">" . $row['member_name'] . "</a>)</span></td>";
  }
  else
  {
    $output .= "
        <td><a href=\"viewmember.php?memberid=" . $row['member_id'] . "\">" . $row['member_name'] . "</a></td>";
  }

  $output .= "
      </tr>";
}

$output .= "
    </table>";

$query = "select drops.item_id, items.item_name, drops.member_id, members.member_name, drops.item_value
          from " . DKP_DROPS . " as drops
          inner join " . DKP_MEMBERS . " as members
          on members.member_id = drops.member_id
          inner join " . DKP_ITEMS . " as items
          on items.item_id = drops.item_id
          where drops.raid_id = $c_raidid";
$result = mysql_query ($query);

echo mysql_error ();

$output .= "
    <span class=\"listtitle\">drops</span>
    <table class=\"list\" cellspacing=\"0\" cellpadding=\"0\">
      <tr class=\"listheader\">
        <td>item</td>
        <td>buyer</td>
        <td>value</td>
      </tr>";

$i = 0;
while ($row = mysql_fetch_array ($result))
{
  $i++;

  $output .= "
      <tr class=\"" . ($i & 1 ? "listodd" : "listeven") . "\">
        <td><a href=\"viewitem.php?itemid=" . $row['item_id'] . "\">" . $row['item_name'] . "</a></td>
        <td><a href=\"viewmember.php?memberid=" . $row['member_id'] . "\">" . $row['member_name'] . "</a></td>
        <td>" . $row['item_value'] . "</td>
      </tr>";
}

$output .= "
    </table>";

$output .= "
  </body>
</html>";

echo $output;

?>
